/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nxlv2.nomad.view.ficheClient;

import com.nxlv2.nomad.accessdb.services.ClientServices;
import com.nxlv2.nomad.businessobjects.Client;
import com.nxlv2.nomad.businessobjects.Contact;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Nastasia
 */
public class ModelTableContact extends AbstractTableModel{
    private List<Contact> contacts;
    private final String[] headers = {"id", "Nom", "Prénom", "Mail", "Téléphone"};
    
    public ModelTableContact(Client client){
        super();
        ClientServices srvCl = new ClientServices();
        contacts = srvCl.getContacts(client);
    }

    @Override
    public int getRowCount() {
        return contacts.size();
    }

    @Override
    public int getColumnCount() {
        return headers.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0:
                return contacts.get(rowIndex).getIdAppli();
            case 1:
                return contacts.get(rowIndex).getNom();
            case 2:
                return contacts.get(rowIndex).getPrenom();
            case 3:
                return contacts.get(rowIndex).getMail();
            case 4:
                return contacts.get(rowIndex).getTel();
            default:
                return null; //Ne devrait jamais arriver
        }
    }
    
    public void addContact(Contact contact){
        contacts.add(contact);
        fireTableRowsInserted(contacts.size()-1, contacts.size()-1);
    }
    
    public void removeContact(int rowIndex){
        contacts.remove(rowIndex);
        fireTableRowsDeleted(rowIndex, rowIndex);
    }
}
